package com.sws.device.util;


import com.sws.device.domain.model.WebSocketMessage;

/**
 * 消息工具类
 * 用于构建WebSocket响应消息
 */
public class MessageUtil {
    
    /**
     * 创建成功响应消息
     *
     * @param msgid  消息ID
     * @param uri    操作URI
     * @param result 结果对象
     * @return 响应消息
     */
    public static WebSocketMessage createSuccessResponse(String msgid, String uri, Object result) {
        WebSocketMessage message = new WebSocketMessage();
        message.setMsgid(msgid);
        
        WebSocketMessage.MessageData data = new WebSocketMessage.MessageData();
        data.setUri(uri);
        data.setCode(200);
        data.setMsg("OK");
        data.setResult(result);
        
        message.setData(data);
        return message;
    }
    
    /**
     * 创建错误响应消息
     *
     * @param msgid    消息ID
     * @param uri      操作URI
     * @param code     错误码
     * @param errorMsg 错误消息
     * @return 响应消息
     */
    public static WebSocketMessage createErrorResponse(String msgid, String uri, int code, String errorMsg) {
        WebSocketMessage message = new WebSocketMessage();
        message.setMsgid(msgid);
        
        WebSocketMessage.MessageData data = new WebSocketMessage.MessageData();
        data.setUri(uri);
        data.setCode(code);
        data.setMsg(errorMsg);
        
        message.setData(data);
        return message;
    }
} 